package com.mykt.exception;

import com.mykt.baseResult.RespondsResult;
import com.mykt.constant.ResultStatusConstants;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
public class GlobalExceptionHandler
{

    /**
     * 系统异常
     */
    @ExceptionHandler(Exception.class)
    public RespondsResult handleException(Exception e, HttpServletRequest request)
    {
        e.printStackTrace();
        return RespondsResult.error(ResultStatusConstants.EXCEPTION_MSG);
    }


    @ExceptionHandler(MyServiceException.class)
    @ResponseBody
    public RespondsResult myServiceException(MyServiceException ex)
    {
        return RespondsResult.error(ex.getMessage());
    }

}
